<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="专业评分主键" prop="majorResultId">
        <el-input
          v-model="queryParams.majorResultId"
          placeholder="请输入专业评分主键"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评分主表主键" prop="inspectionId">
        <el-input
          v-model="queryParams.inspectionId"
          placeholder="请输入评分主表主键"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目主键" prop="itemId">
        <el-input
          v-model="queryParams.itemId"
          placeholder="请输入项目主键"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业主键" prop="majorId">
        <el-input
          v-model="queryParams.majorId"
          placeholder="请输入专业主键"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业简称" prop="majorName">
        <el-input
          v-model="queryParams.majorName"
          placeholder="请输入专业简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标准得分" prop="itemStandardScore">
        <el-input
          v-model="queryParams.itemStandardScore"
          placeholder="请输入标准得分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考核得分" prop="itemScoreResult">
        <el-input
          v-model="queryParams.itemScoreResult"
          placeholder="请输入考核得分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排序" prop="sorting">
        <el-input
          v-model="queryParams.sorting"
          placeholder="请输入排序"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="createByName">
        <el-input
          v-model="queryParams.createByName"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createAt">
        <el-date-picker clearable
          v-model="queryParams.createAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新人" prop="updateByName">
        <el-input
          v-model="queryParams.updateByName"
          placeholder="请输入更新人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updateAt">
        <el-date-picker clearable
          v-model="queryParams.updateAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="版本" prop="version">
        <el-input
          v-model="queryParams.version"
          placeholder="请输入版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="扩展字段1" prop="extra1">
        <el-input
          v-model="queryParams.extra1"
          placeholder="请输入扩展字段1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="扩展字段2" prop="extra2">
        <el-input
          v-model="queryParams.extra2"
          placeholder="请输入扩展字段2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="扩展字段3" prop="extra3">
        <el-input
          v-model="queryParams.extra3"
          placeholder="请输入扩展字段3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['workSafetyStandardization:InspectionItem:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['workSafetyStandardization:InspectionItem:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['workSafetyStandardization:InspectionItem:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['workSafetyStandardization:InspectionItem:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="InspectionItemList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目评分主键" align="center" prop="itemResultId" />
      <el-table-column label="专业评分主键" align="center" prop="majorResultId" />
      <el-table-column label="评分主表主键" align="center" prop="inspectionId" />
      <el-table-column label="项目主键" align="center" prop="itemId" />
      <el-table-column label="专业主键" align="center" prop="majorId" />
      <el-table-column label="专业简称" align="center" prop="majorName" />
      <el-table-column label="项目名称" align="center" prop="itemName" />
      <el-table-column label="标准得分" align="center" prop="itemStandardScore" />
      <el-table-column label="考核得分" align="center" prop="itemScoreResult" />
      <el-table-column label="排序" align="center" prop="sorting" />
      <el-table-column label="创建人" align="center" prop="createByName" />
      <el-table-column label="创建时间" align="center" prop="createAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateByName" />
      <el-table-column label="更新时间" align="center" prop="updateAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注说明" align="center" prop="remark" />
      <el-table-column label="版本" align="center" prop="version" />
      <el-table-column label="状态, 默认1(1:正常；2:冻结；98:关闭；99:删除)；" align="center" prop="status" />
      <el-table-column label="扩展字段1" align="center" prop="extra1" />
      <el-table-column label="扩展字段2" align="center" prop="extra2" />
      <el-table-column label="扩展字段3" align="center" prop="extra3" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['workSafetyStandardization:InspectionItem:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['workSafetyStandardization:InspectionItem:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改标准化考核--项目得分对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="专业评分主键" prop="majorResultId">
          <el-input v-model="form.majorResultId" placeholder="请输入专业评分主键" />
        </el-form-item>
        <el-form-item label="评分主表主键" prop="inspectionId">
          <el-input v-model="form.inspectionId" placeholder="请输入评分主表主键" />
        </el-form-item>
        <el-form-item label="项目主键" prop="itemId">
          <el-input v-model="form.itemId" placeholder="请输入项目主键" />
        </el-form-item>
        <el-form-item label="专业主键" prop="majorId">
          <el-input v-model="form.majorId" placeholder="请输入专业主键" />
        </el-form-item>
        <el-form-item label="专业简称" prop="majorName">
          <el-input v-model="form.majorName" placeholder="请输入专业简称" />
        </el-form-item>
        <el-form-item label="项目名称" prop="itemName">
          <el-input v-model="form.itemName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="标准得分" prop="itemStandardScore">
          <el-input v-model="form.itemStandardScore" placeholder="请输入标准得分" />
        </el-form-item>
        <el-form-item label="考核得分" prop="itemScoreResult">
          <el-input v-model="form.itemScoreResult" placeholder="请输入考核得分" />
        </el-form-item>
        <el-form-item label="排序" prop="sorting">
          <el-input v-model="form.sorting" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="创建人" prop="createByName">
          <el-input v-model="form.createByName" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createAt">
          <el-date-picker clearable
            v-model="form.createAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新人" prop="updateByName">
          <el-input v-model="form.updateByName" placeholder="请输入更新人" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updateAt">
          <el-date-picker clearable
            v-model="form.updateAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注说明" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="版本" prop="version">
          <el-input v-model="form.version" placeholder="请输入版本" />
        </el-form-item>
        <el-form-item label="扩展字段1" prop="extra1">
          <el-input v-model="form.extra1" placeholder="请输入扩展字段1" />
        </el-form-item>
        <el-form-item label="扩展字段2" prop="extra2">
          <el-input v-model="form.extra2" placeholder="请输入扩展字段2" />
        </el-form-item>
        <el-form-item label="扩展字段3" prop="extra3">
          <el-input v-model="form.extra3" placeholder="请输入扩展字段3" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInspectionItem, getInspectionItem, delInspectionItem, addInspectionItem, updateInspectionItem } from "@/api/workSafetyStandardization/InspectionItem";

export default {
  name: "InspectionItem",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 标准化考核--项目得分表格数据
      InspectionItemList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        majorResultId: null,
        inspectionId: null,
        itemId: null,
        majorId: null,
        majorName: null,
        itemName: null,
        itemStandardScore: null,
        itemScoreResult: null,
        sorting: null,
        createByName: null,
        createAt: null,
        updateByName: null,
        updateAt: null,
        version: null,
        status: null,
        extra1: null,
        extra2: null,
        extra3: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询标准化考核--项目得分列表 */
    getList() {
      this.loading = true;
      listInspectionItem(this.queryParams).then(response => {
        this.InspectionItemList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        itemResultId: null,
        majorResultId: null,
        inspectionId: null,
        itemId: null,
        majorId: null,
        majorName: null,
        itemName: null,
        itemStandardScore: null,
        itemScoreResult: null,
        sorting: null,
        createBy: null,
        createByName: null,
        createAt: null,
        updateBy: null,
        updateByName: null,
        updateAt: null,
        remark: null,
        version: null,
        status: null,
        extra1: null,
        extra2: null,
        extra3: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.itemResultId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加标准化考核--项目得分";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const itemResultId = row.itemResultId || this.ids
      getInspectionItem(itemResultId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改标准化考核--项目得分";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.itemResultId != null) {
            updateInspectionItem(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInspectionItem(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const itemResultIds = row.itemResultId || this.ids;
      this.$modal.confirm('是否确认删除标准化考核--项目得分编号为"' + itemResultIds + '"的数据项？').then(function() {
        return delInspectionItem(itemResultIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('workSafetyStandardization/InspectionItem/export', {
        ...this.queryParams
      }, `InspectionItem_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
